package main
import (
    "encoding/json"
    "fmt"
    "os"
    
)
type BinStruct struct{
	FileName string
    Addr uint32
}

type Cfg struct {
   	Manufacturers string
    Product uint32
    Boot BinStruct
    App0 BinStruct
}

var UserCfg Cfg

var cfile = "config.json"
func printCfg() {
	fmt.Printf("读取配置文件\"%s\"成功\r\n", cfile)
	fmt.Printf("Manufacturers\t: 0x%08X\r\n", UserCfg.Manufacturers)
	fmt.Printf("Product\t\t: 0x%08X\r\n", UserCfg.Product)
	fmt.Printf("Boot\t\t: %s\t0x%08X\r\n", UserCfg.Boot.FileName, UserCfg.Boot.Addr)
	fmt.Printf("App0\t\t: %s\t0x%08X\r\n", UserCfg.App0.FileName, UserCfg.App0.Addr)
}

func init() {
    fd, err := os.Open(cfile)
	if err != nil {
		fmt.Println("open %s faild", cfile)
		os.Exit(1)
	}
    defer fd.Close()
    decoder := json.NewDecoder(fd)
    err = decoder.Decode(&UserCfg)
    if err != nil {
        fmt.Println("parse %s faild", cfile)
		os.Exit(1)
    }
    printCfg()
}